package cn.woochen.mvvmframe.activity

import android.content.Context
import android.content.Intent
import android.graphics.Color
import cn.woochen.comlib.span.SpanBean
import cn.woochen.comlib.span.SpanUtil
import cn.woochen.comlib.util.ext.showToast
import cn.woochen.mvvmframe.R
import cn.woochen.mvvmframe.config.BaseActivity
import cn.woochen.mvvmframe.databinding.ActivitySpanTextBinding
import cn.woochen.mvvmframe.viewmodels.EmptyViewModel

/**
 *类描述：富文本处理演示类
 *@author woochen
 *@time 2021/8/24 10:52
 */
class SpanTextActivity : BaseActivity<ActivitySpanTextBinding, EmptyViewModel>() {

    private val content = "我们非常重视您的个人信息和隐私保护，为了更好地保障您的个人权益，在您使用我们的产品前，请务必审慎阅读《用户协议》和《隐私协议》，尤其是：\n" + "1.我们对您的个人信息的收集/保存/使用/对外提供/保护等规则条款，以及您的用户权利等条款；\n" + "2.约定我们的限制责任，免责条款。"

    override fun setContentView(): Int = R.layout.activity_span_text

    override fun initData() {
        initWidgets()
    }

    private fun initWidgets() {
        val transStr = SpanUtil.transStr(mBinding.tvSpan,content, SpanBean("《用户协议》",
            Color.parseColor("#ff0000")) { showToast("用户协议") },
            SpanBean("《隐私协议》", Color.parseColor("#00ff00")) { showToast("隐私协议") })
        mBinding.tvSpan.text = transStr
    }

    companion object{
        fun start(context: Context){
            val intent = Intent(context,SpanTextActivity::class.java)
            context.startActivity(intent)
        }
    }

}